<?php

namespace Plugins\AdminBasic\Http\Admin\Service\Logins;

use App\Exception\ApiMessageException;
use App\Http\Admin\Service\Logins\DefaultLoginService;
use App\Interfaces\AdminLoginServiceInterface;
use Plugins\AdminBasic\Enums\BasicAdministratorsEnumStatus;
use Plugins\AdminBasic\Models\BasicAdministrators;

class AdministratorsLoginService extends DefaultLoginService implements AdminLoginServiceInterface
{
    protected string $model = BasicAdministrators::class;

    /**
     * @param BasicAdministrators $model
     * @return void
     * @throws ApiMessageException
     */
    public function customVerify($model): void
    {
        if ($model->status != BasicAdministratorsEnumStatus::Normal) {
            throw new ApiMessageException('账号被禁用');
        }
        $model->lately_time = date('Y-m-d H:i:s');
        $model->save();
    }

}